<?php

use yii\helpers\Html;
use eric\widgets\GridView;
use eric\widgets\Modal;

/* @var $this yii\web\View */
/* @var $searchModel app\models\ChannelSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = Yii::t('app', '频道管理');
$this->params['breadcrumbs'][] = $this->title;
?>
<!--BEGIN HEADER-->
<div class="section-header">
    <h3 class="text-standard">
        <i class="fa fa-fw fa-arrow-circle-right text-gray-light"></i>
        <?=$this->title?><small><?=$this->subTitle?></small>
    </h3>
</div>
<!--END HEADER-->
<!--BEGIN BODY-->
<div class="section-body">
    <div class="channel-index">
                        <?php // echo $this->render('_search', ['model' => $searchModel]); ?>
                <p>
            <?= Html::a(Yii::t('app', '添加{modelClass}', [
    'modelClass' => '频道',
]), ['create?partial=1'], [
                'class' => 'btn btn-support1',
                'data-toggle' => 'modal',
                'data-target' => '#channel_modal'
            ]) ?>
        </p>

                    <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'options' => ['id' => 'channel_grid'],
            'filterModel' => $searchModel,
           'columns' => [
//                        'cid',
            'cname',
//            'manager_id',
//            'update_time',
            // 'fid',
             'list_template',
             'show_template',
//             'display',
               [
                   'attribute'=>'display',
                   'value'=>function($model,$key,$index,$grid){
                       return $model->display==1 ? '展示' :'不展示';
                   },
                   'filter'=>[1=>'展示',0=>'不展示'],
               ],
//               'create_time',
            // 'type',
            // 'seq',
            [
                'class' => 'eric\widgets\ActionColumn',
                'modalId' => 'channel_modal',

            ],
            ],
            ]); ?>
        
    </div>
</div>
<!--END BODY-->
<?php
    Modal::begin([
        'options' => [
            'id' => 'channel_modal'
        ],
        'size'=>Modal::SIZE_LARGE,
        'header' => 'channel panel',
    ]);
    Modal::end();
?>
<script type="text/javascript">
    $(document).on("click","#channel_type input",function(){
        var obj=$("#channel_type input");
        $.ajax({
            type:'post',
            url:'/admin/channel/data',
            dataType:'json',
            success:function(e){
                for(var i=0; i<obj.length; i ++){
                    if(obj[i].checked){
                        if(obj[i].value==1){
//                            alert(e.data);
                            $("#channel_list_template").html(e.data);
                        }else if(obj[i].value==2){
//                            alert(e.data1);
                            $("#channel_list_template").html(e.data1);
                        }
                    }
                }
            }

        });
    });

</script>
<script type="text/javascript">
    function del(id,fid){
        var rows="";
        if(confirm('确定要删除吗?')){
            $.ajax({
                'type':"post",
                'url':"/admin/channel/del?id="+id,
                data:'fid='+fid,
                dataType:'json',
                success:function(msg){
                    if(msg.err=='ok'){
//                     window.location.href='/admin/nature/view?id='+pnid+'&partial=1';
//                     window.location.reload(true);
//                    console.info(msg.data);return false;
                        for(i=0;i<msg.data.length;i++){
                            var json_string=msg.data[i];
                            rows +="<tr><td style='text-align:center;'>"+json_string.cname+"</td><td style='text-align:center;'><a href='#' id='nid' onclick='del("+json_string.cid+","+json_string.fid+")'>删除</a></td></tr>";
                        }
//                    console.info(rows);
                        if(rows) {
                            $("#name1").html(rows);
                        }else{
                            $("#name1").attr("border","0");
                            $("#name1").html("No results found.");
                        }

                    }
                }

            })
        }
    }

</script>
